<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.ok{
			    color:green;
			}
			.error{
			    color:red;
			}
		</style>
	</head>
	<body>
		名字<input type="text" id="name" onblur="checkName()"/>
		<span  id="nameMsg">5-10位的字母、数字、下划线</span>
		<br/>
		
		邮箱<input type="text" id="email" onblur="checkEmail()"/>
		<span id="emailMsg">必须符合邮箱的格式</span>
		
		<script type="text/javascript">
			function checkName() {
				var name = document.getElementById('name').value;
				var nameSpan = document.getElementById('nameMsg');
				var regex = /[a-zA-Z0-9_]{5,10}/;
				if (regex.test(name)) {
					nameSpan.className = 'ok';
				} else {
					nameSpan.className = 'error';
				}
			}
			
			function checkEmail() {
				var email = document.getElementById('email').value;
				var emailSpan = document.getElementById('emailMsg');
				var regex = /[a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+/;
				if (regex.test(email)) {
					emailSpan.className = 'ok';
				} else {
					emailSpan.className = 'error';
				}
			}
		</script>
	</body>
</html>
